<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>组件细节</title>
    <script src="js/vue.js"></script>
</head>
<body>
    <div id="root">
        <contant ref="one" @change="handleChange"></contant>
        <contant ref="two" @change="handleChange"></contant>
        <div>{{total}}</div>
    </div>
    <script>
        Vue.component("contant",{
            template: "<div @click='handleClick'>{{number}}</div>",
            data: function () {
                return {
                    number:0
                }
            },
            methods: {
                handleClick: function () {
                    this.number++;
                    // 当子组件发生变化的时候，同时向外面告诉一个事件change,
                    // 在父组件上监听@change方法同时触发父组件handleChange方法
                    this.$emit('change')
                }
            }
        })
        var vm = new Vue({
            el: "#root",
            data: {
                total: 0
            },
            methods: {
                handleChange: function () {
                    this.total = this.$refs.one.number + this.$refs.two.number
                }
            }
        })
    </script>
</body>
</html>